package exp2.test3;

import ch16.LinkedBinaryTree;

import java.util.Scanner;

public class Game
{
    private LinkedBinaryTree<String> tree;
    //-----------------------------------------------------------------
// Sets up the diagnosis question tree.
//-----------------------------------------------------------------
    public Game()
    {
        String e1 = "它是名人吗？";
        String e2 = ".他是学生吗？";
        String e3 = "他是运动员吗？";
        String e4 = "他是老师吗？";
        String e5 = "他是男生吗？";
        String e6 = "他是演员吗？";
        String e7 = "他是梅西";
        String e8 = "他是格茸";
        String e9 = "他是张志云";
        String e10 = "她是道巴";
        String e11 = "他是杨顺";
        String e12 = "他是赵雷";
        String e13 = "他是成龙";
        LinkedBinaryTree<String> n2, n3, n4, n5, n6, n7, n8, n9,
                n10, n11, n12, n13;
        n8 = new LinkedBinaryTree<String>(e8);
        n9 = new LinkedBinaryTree<String>(e9);
        n4 = new LinkedBinaryTree<String>(e4, n8, n9);
        n10 = new LinkedBinaryTree<String>(e10);
        n11 = new LinkedBinaryTree<String>(e11);
        n5 = new LinkedBinaryTree<String>(e5, n10, n11);
        n12 = new LinkedBinaryTree<String>(e12);
        n13 = new LinkedBinaryTree<String>(e13);
        n6 = new LinkedBinaryTree<String>(e6, n12, n13);
        n7 = new LinkedBinaryTree<String>(e7);
        n2 = new LinkedBinaryTree<String>(e2, n4, n5);
        n3 = new LinkedBinaryTree<String>(e3, n6, n7);
        tree = new LinkedBinaryTree<String>(e1, n2, n3);
    }
    //-----------------------------------------------------------------
// Follows the diagnosis tree based on user responses.
//-----------------------------------------------------------------
    public void diagnose()
    {
        Scanner scan = new Scanner(System.in);
        LinkedBinaryTree<String> current = tree;
        System.out.println ("So, you're having back pain.");
        while (current.size() > 1)
        {
            System.out.println (current.getRootElement());
            if (scan.nextLine().equalsIgnoreCase("N"))
                current = current.getLeft();
            else
                current =  current.getRight();
        }
        System.out.println (current.getRootElement());
    }
}
